<template>
  <div>
    <div>
      <div
        style="
          display: flex;
          align-items: center;
          font-size: 16px;
          margin-bottom: 10px;
        "
      >
        <van-image
          width="30"
          height="30"
          src="https://zehao.oss-cn-beijing.aliyuncs.com/logo.jpg"
        />
        <span style="margin-left: 10px">TQozon官方认证</span>
      </div>
      <div style="color: blue; font-size: 16px; margin-bottom: 20px">
        官网：<a target="_blank" href="https://www.tqozon.com"
          >www.tqozon.com</a
        >
      </div>
    </div>

    <van-dialog
      width="800px"
      v-model:show="show"
      title="跟卖"
      :before-close="beforeClose"
      show-cancel-button
      @confirm="onSubmit"
    >
      <div class="wrapper">
        <van-form @submit="onSubmit">
          <div class="div_title">店铺选择(支持多选)</div>
          <div class="store_list">
            <van-checkbox-group
              v-model="submitForm.checkStores"
              direction="horizontal"
            >
              <van-cell-group>
                <!-- <van-cell
                v-for="(item, index) in storeList"
                clickable
                :key="item.id"
                :title="`${item.storeName}`"
                @click="toggle(index)"
              >
                <template #right-icon>
                  <van-checkbox :name="item" ref="checkboxes" />
                </template>
              </van-cell> -->
                <div
                  class="check-item"
                  v-for="(item, index) in storeList"
                  :key="index"
                >
                  <van-checkbox
                    :name="`${item.id}`"
                    @click="toggle(index)"
                    ref="checkboxes"
                    >{{ item.storeName }}</van-checkbox
                  >
                </div>
              </van-cell-group>
            </van-checkbox-group>
          </div>
          <!-- <van-field name="switch" label="AI改图">
          <template #input>
            <span>改图</span>
            <van-switch v-model="switchChecked" size="20" />
            <span>不改图</span>
          </template>
        </van-field> -->
          <van-field name="switch" label="品牌">
            <template #input>
              <span>不携带</span>
              <van-switch v-model="submitForm.brandChecked" size="20" />
              <span>携带</span>
            </template>
          </van-field>
          <van-field name="switch" label="类型">
            <template #input>
              <span>复制</span>
              <van-switch v-model="submitForm.typeChecked" size="20" />
              <span>跟卖</span>
            </template>
          </van-field>
          <van-field
            v-model="submitForm.price"
            center
            clearable
            label="输入价格"
            placeholder="输入价格"
          >
            <template #button>
              <van-button size="small" @click="onePrice" type="primary"
                >价格一键设置</van-button
              >
            </template>
          </van-field>
          <van-field
            v-model="submitForm.preSku"
            label-width="260"
            label="货号前缀（不输入则默认‘sku-随机数’）"
            placeholder="输入前缀"
          />
          <!-- <van-field
          v-model="submitForm.genmai"
          center
          clearable
          label="跟卖"
          placeholder="跟卖"
        >
          <template #button>
            <van-button size="small" type="primary">人民币跟卖</van-button>
            <van-button size="small" type="primary">美元跟卖</van-button>
          </template>
        </van-field> -->

          <div class="tongyi_div">
            <van-button
              size="small"
              style="padding: 0 20px"
              @click="genmaiDefault"
              type="primary"
              >跟卖</van-button
            >
            <div class="handle_div">
              <span class="label">统一增加</span>
              <input v-model="submitForm.addPrice" />
              <van-button size="small" type="primary" @click="addPrice"
                >统一增加</van-button
              >
            </div>
            <div class="handle_div">
              <span class="label">统一减少</span>
              <input v-model="submitForm.subPrice" />
              <van-button size="small" @click="subPrice" type="primary"
                >统一减少</van-button
              >
            </div>
          </div>

          <div>温馨提示：只会跟卖您设置了价格的商品！统一增加减少</div>
          <div class="sku_list">
            <div
              class="sku_item"
              v-for="(item, index) in this.skuList"
              :key="index"
            >
              <!-- <div class="sku_name" v-if="item.data">
              {{ item.data.searchableText }}
            </div> -->
              <!-- <van-image
              width="40"
              height="40"
              v-if="item.data"
              :src="item.data.coverImage"
            /> -->
              <div class="sku_name">SKU:{{ item.sku }}</div>
              <input v-model="item.resultPrice" style="width: 80px" />
              <div class="sku_name" v-if="item.data && item.data.price">
                现价:{{ item.data.price }}
              </div>
              <div class="sku_name" v-if="item.data && item.data.originalPrice">
                原价:{{ item.data.originalPrice }}
              </div>
            </div>
          </div>
        </van-form>
      </div>
    </van-dialog>

    <span v-if="active == false" style="font-size: 12px"
      >TqOzon提示：当前账户权限不足,请使用激活码激活！</span
    >
    <van-button
      @click="createDetailHome"
      style="margin-top: 20px"
      type="primary"
      v-if="this.sku == ''"
      size="large"
      >加载更多</van-button
    >
    <van-button
      @click="caiji"
      style="margin-top: 20px"
      v-if="this.sku != ''"
      type="primary"
      size="large"
      >一键采集</van-button
    >
    <van-button
      @click="loginOut"
      style="margin-top: 20px"
      type="danger"
      size="large"
      >退出登录</van-button
    >
  </div>
</template>

<script>
/* eslint-disable */
import {ref, onBeforeUpdate} from "vue";
import axiosInstance from "@/api.js";
import Cookies from "js-cookie";
import router from "@/router.js";
import {showNotify} from "vant";
import {showToast} from "vant";
import {baseURL} from "@/constant.js";
export default {
  data() {
    return {
      active: Cookies.get("active") == "true",
      submitForm: {
        checkStores: [],
        brandChecked: false,
        typeChecked: false,
        price: "",
        preSku: "",
      },
      list: ["a", "b", "a", "b", "a", "b"],
      show: false,
      checked: [],
      sku: "",
      checkboxRefs: [],
      skuList: [],
      storeList: [],
      da: {},
      isPass: false,
      pageSkuIds: [],
      pageSkuList: [],
      terx: "采集",
      skuDetail: {},
      complete: true,
      logoImg: "https://zehao.oss-cn-beijing.aliyuncs.com/logo.jpg",
    };
  },
  setup() {},
  mounted() {
    setTimeout(() => {
      let sku = "";
      if (location.href.startsWith("https://www.ozon.ru/product")) {
        let targetScript = document.getElementsByTagName("script");
        console.log("location.href:" + location.href);
        for (let i in targetScript) {
          try {
            if (
              targetScript[i].hasAttribute("type") &&
              targetScript[i].getAttribute("type") == "application/ld+json"
            ) {
              sku = JSON.parse(targetScript[i].innerText)["sku"];
              this.sku = sku;
              if (Cookies.get("token")) {
                this.getProductDetail();
              }
              console.log("sku:" + this.sku);
              break;
            }
          } catch (error) {
          } finally {
          }
        }
      } else {
        this.createDetailHome();
      }
    }, 1000);
  },
  watch: {
    // submitForm: {
    //   deep: true,
    //   handler(newVal, oldVal) {
    //     //newVal和oldVal会包含formData里面的每一个属性值
    //     console.log(newVal, oldVal);
    //   },
    // },
  },
  methods: {
    beforeClose(action) {
      console.log("action:" + action);
      if (action === "confirm") {
        return new Promise(async (resolve) => {
          if (this.submitForm.checkStores.length == 0) {
            showToast("请至少选择一家店铺");
            return resolve(false);
          }
          let skus = [];
          this.skuList.forEach((item) => {
            if (item["resultPrice"]) {
              skus.replace({
                sku: item["sku"],
                price: item["resultPrice"],
              });
            }
          });
          if (skus.length == 0) {
            showToast("请至少选择一个sku");
            return resolve(false);
          }
          console.log(this.submitForm);
          let retJson = await axiosInstance.post(
            `${baseURL}/api/submitProduct`,
            {
              formData: this.submitForm,
              skuList: skus,
            }
          );
          // showToast(JSON.stringify(retJson));
          if (retJson["data"]["code"] == 0) {
            showToast("提交成功，请耐心等待上传");
            resolve(true);
          } else {
            showToast("上传失败" + retJson["data"]["msg"]);
            resolve(false);
          }
        });
      } else {
        return true;
      }
    },
    async onSubmit() {},
    onePrice() {
      const _this = this;
      this.skuList.forEach((item) => {
        item.resultPrice = parseFloat(_this.submitForm.price);
      });
    },
    addPrice() {
      const _this = this;
      if (!_this.submitForm.addPrice) {
        showToast("请输入价格");
        return;
      }
      this.skuList.forEach((item) => {
        let price = item.data.price
          .trim()
          .replace(",", ".")
          .replace(" ", "")
          .replace("₽", "")
          .replace("$", "");
        item.resultPrice =
          parseFloat(price) + parseFloat(_this.submitForm.addPrice);
      });
    },
    subPrice() {
      const _this = this;
      if (!_this.submitForm.subPrice) {
        showToast("请输入价格");
        return;
      }
      this.skuList.forEach((item) => {
        let price = item.data.price
          .trim()
          .replace(",", ".")
          .replace(" ", "")
          .replace("₽", "")
          .replace("$", "");
        item.resultPrice =
          parseFloat(price) - parseFloat(_this.submitForm.subPrice);
      });
    },
    toggle(index) {
      this.$refs.checkboxes[index].toggle();
    },
    loginOut() {
      Cookies.remove("token");
      router.replace("/login");
    },
    async getProductDetail() {
      if (this.active) {
        const queryString = new URLSearchParams({sku: this.sku}).toString();
        // 发送 POST 请求
        let retJson = await axiosInstance.get(
          `${baseURL}/api/getProductDetail?${queryString}`
        );
        let items = retJson["data"]["data"];
        let item = items[0];
        if (!item) {
          item = {sku: this.sku};
        }
        this.skuDetail = item;
        this.da = item;
        this.createDetail();
        let container = document.querySelector("#detail-content-app");

        this.appendLine(`TQozon`, container, "black", true);
        this.appendLine(`sku：${item["sku"]}`, container);
        this.appendLine(`品牌：${item["brand"]}`, container);
        this.appendLine(
          `类目：${item["category1"]}/${item["category2"]}/${item["category3"]}`,
          container
        );
        this.appendLine(
          `月销售额：${item["soldSum"]}₽ 月销售额排名：前${item["sellSumRating"]}%`,
          container
        );
        this.appendLine(
          `月销量：${item["soldCount"]} 月销量排名：前${item["companyCountRange"]}%`,
          container,
          "red"
        );
        this.appendLine(
          `月浏览量：${item["sessionCount"]} 购物车转化率：前${item["convToCartPdp"]}%`,
          container
        );
        this.appendLine(
          `销售该商家的卖家数量：${item["companyCountRange"]}`,
          container
        );
        this.appendLine(`体积,公升：${item["volume"]} 公升`, container);
        this.appendLine(`平均价格：${item["avgPrice"]}₽`, container);
        // this.appendLine(`卖家类型：${item["sources"]} `);
        // this.appendLine(
        //   `能够跟卖：${item["blockedBySeller"] == false ? "能" : "不能"} `
        // );
      }
    },
    // 获取详情
    async requestDetail(sku) {
      const queryString = new URLSearchParams({sku: sku}).toString();
      let retJson = await axiosInstance.get(
        `${baseURL}/api/getProductDetail?${queryString}`
      );
      let items = retJson["data"]["data"];
      return items;
    },
    async getProductDetailItem(sku, items, container) {
      console.log(this.active);
      if (this.active && container) {
        console.log(222222);
        let item = items[0];
        if (!item) {
          item = {sku: this.sku};
        }
        console.log(item);
        this.appendLineItem(`TQozon`, container, "black", true);
        this.appendLineItem(
          `sku：${item["sku"] ? item["sku"] : ""}`,
          container
        );
        this.appendLineItem(
          `品牌：${item["brand"] ? item["brand"] : ""}`,
          container
        );
        this.appendLineItem(
          `类目：${item["category1"]}/${item["category2"]}/${item["category3"]}`,
          container
        );
        this.appendLineItem(
          `月销售额：${
            item["soldSum"] ? item["soldSum"] : ""
          }₽ 月销售额排名：前${
            item["sellSumRating"] ? item["sellSumRating"] : ""
          }%`,
          container
        );
        this.appendLineItem(
          `月销量：${
            item["soldCount"] ? item["soldCount"] : ""
          } 月销量排名：前${
            item["companyCountRange"] ? item["companyCountRange"] : ""
          }%`,
          container,
          "red"
        );
        this.appendLineItem(
          `月浏览量：${
            item["sessionCount"] ? item["sessionCount"] : ""
          } 购物车转化率：前${
            item["convToCartPdp"] ? item["convToCartPdp"] : ""
          }%`,
          container
        );
        this.appendLineItem(
          `销售该商家的卖家数量：${
            item["companyCountRange"] ? item["companyCountRange"] : ""
          }`,
          container
        );
        this.appendLineItem(
          `体积,公升：${item["volume"] ? item["volume"] : ""} 公升`,
          container
        );
        this.appendLineItem(
          `平均价格：${item["avgPrice"] ? item["avgPrice"] : ""}₽`,
          container
        );
        this.appendLineItem(`采集`, container, null, null, true, item);
      }
    },

    async createDetailHome() {
      if (this.complete == false) {
        alert("等待本次数据加载完成");
        return;
      }
      this.complete = false;
      let eles = null;
      let selectors = [
        ".iu7.ui7.iv0.j1o",
        "#layoutPage .i2u.m4j.jm6",
        "#layoutPage .i2u.m4j.j6m",
        "#layoutPage .ti7.it8.ui0.nj8",
        "#layoutPage .i7.it8.ui0.n1j",
        "#layoutPage .x1i",
        "#layoutPage .ui2.iu3.iu6.j3m.mj4",
        "#layoutPage .xi2",
        "#layoutPage .u1i.i2u.i5u.nj6",
        "#layoutPage .xi6",
        "#layoutPage .ui2.iu3.iu6.j3m.jm4",
        "#layoutPage .ui2.iu3.iu6.j7n",
        "#layoutPage .xi9",
        "#layoutPage .t7i.mj.j1m",
        "#layoutPage .t7i.mj.jm1",
        "#layoutPage .hb4.hb7",
        "#layoutPage .i7x",
        "t7i.mj.jm1",
        ".u6i.i7u.vi",
        "#layoutPage .ui2.iu3.iu6.oj3",
        "#layoutPage .ti8.mj0.jm2",
        "#layoutPage .ti8.mj0.m1j",
        "#layoutPage .lz3.l5z",
        "#layoutPage .i8t.t8i.i1u.nj2",
        "#layoutPage .ah1.ha1.ha4",
        "#layoutPage .ag7.af0c",
        "#layoutPage .a2h.h2a.h5a",
        "#layoutPage .jb6 .bj2.bj5",
        "#layoutPage .i4v.i5v",
        "#layoutPage .g6a.afc",
        "#layoutPage .g6a.e9ac",
        "#layoutPage .i8v.vi8",
        "#paginatorContent .v4i",
        "#paginatorContent .vi6.v6i",
        "#paginatorContent .vi0.vi1",
        "#layoutPage .ah1.ha1.ha4",
        "#layoutPage .ag7.af0c",
        "#layoutPage .a2h.h2a.h5a",
        "#layoutPage .jb6 .bj2.bj5",
        "#layoutPage .i4v.i5v",
        "#layoutPage .g6a.afc",
        "#layoutPage .g6a.e9ac",
        "#layoutPage .i8v.vi8",
        "#paginatorContent .v4i",
        "#paginatorContent .vi6.v6i",
        "#paginatorContent .vi0.vi1",
        'div[data-widget="megaPaginator"] div.cf2a > div',
        'div[data-widget="hammers"] > div:nth-child(2) > div > div',
        'div[data-widget="skuGridSimple"] div.cf2a > div',
        'div[data-widget="searchResultsV2"] .tile-root',

        'div[data-widget="skuGridSimple"] > div:nth-child(2) > div',
        '#paginatorContent div[data-widget="searchResultsV2"] >div > div:not(.tqozon_cla)',
      ];
      let count = 0;
      let flag = false;
      for (let i in selectors) {
        if (document.querySelector(selectors[i])) {
          flag = true;
          eles = document.querySelectorAll(selectors[i]);
          for (let j in eles) {
            try {
              let ele = eles[j];
              if (ele && typeof ele.querySelector === "function") {
                let a_ele = ele.querySelector("a");
                let href = a_ele.getAttribute("href");
                let paths = href.split("/");
                let path = paths[2];
                paths = path.split("-");
                let sku = paths[paths.length - 1];
                if (ele.querySelector("#tq_" + sku)) {
                  continue;
                }
                this.pageSkuIds.push(sku);
                let items = await this.requestDetail(sku);
                let container = this.cerateItemDetail(ele, sku, selectors[i]);
                console.log(items);
                await this.getProductDetailItem(sku, items, container);
                count += 1;
                if (count >= 16) {
                  break;
                }
              } else {
                console.log("not a function");
              }
            } catch (error) {
              console.error(error);
              break;
            } finally {
            }
          }
        }
      }
      console.log("flag:" + flag);
      this.complete = true;
    },
    cerateItemDetail(ele, sku, selector) {
      let container = document.createElement("div");
      container.setAttribute("id", "tq_" + sku);
      container.setAttribute(
        "style",
        "    position: relative;\n" +
          "    display: flex;\n" +
          "    width: 98%;\n" +
          "    min-height: 320px;\n" +
          "    margin: 0 auto;\n" +
          "    padding: 5px;\n" +
          "    flex-direction: column;\n" +
          // "    justify-content: flex-start;\n" +
          // "    justify-content: center;\n" +
          "    background: white;\n" +
          "    border: 1px solid rgba(0, 0, 0, 0.05);\n" +
          "    box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.1);\n" +
          // "    border-radius: 12px;\nz-index:999;\n" +
          "    box-sizing: border-box;\n"
      );

      if (
        selector == "#paginatorContent .v4i" ||
        selector == "#layoutPage .i8v.vi8"
      ) {
        ele.insertAdjacentElement("afterend", container);
      } else {
        ele.appendChild(container);
      }
      return container;
    },
    async createDetail() {
      const container = document.createElement("div");
      container.setAttribute("id", "detail-content-app");
      container.setAttribute(
        "style",
        "    position: relative;\n" +
          "    display: flex;\n" +
          // "    width: 386px;\n" +
          "    height: 400px;\n" +
          "    padding: 15px;\n" +
          "    flex-direction: column;\n" +
          // "    justify-content: flex-start;\n" +
          // "    justify-content: center;\n" +
          "    background: white;\n" +
          "    border: 1px solid rgba(0, 0, 0, 0.05);\n" +
          "    box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.1);\n" +
          "    border-radius: 12px;\nz-index:999;\n" +
          "    box-sizing: border-box;\n"
      );
      let ele = null;
      let selectors = [
        ".y8l",
        ".lz3.l5z",
        ".z8l.l9z",
        "#layoutPage > div.b2 .l2r.rl4",
        "#layoutPage > div.b2 > div.container.b6 > div.qk5.k0r > div.qk5.k1r.q8k.kq9 > div.qk5.k1r.q8k.k9q > div.ql9.l1r",
        "#layoutPage > div.b2 > div.container.b6 > div.q5k.rk0 > div.q5k.rk1.kq9.k9q > div.q5k.rk1.kq9.qk9 > div",
        "#layoutPage > div.b2 > div.container.b6 > div.q6k.rk1 > div.q6k.rk2.kr.rk > div.q6k.rk2.kr.kr0",
        "#layoutPage > div.b2 > div.container.b6 .lr1.rl1",
        'div[data-widget="webSale"]',
      ];

      for (let i in selectors) {
        if (document.querySelector(selectors[i])) {
          ele = document.querySelector(selectors[i]);
        }
      }
      if (ele) {
        ele.appendChild(container);
      } else {
        console.log("找不到挂载节点");
      }
    },

    async appendLineItem(str, container, color, logo, b = false, item) {
      if (!color) {
        color = "black";
      }
      let wrapperEle = document.createElement("div");
      wrapperEle.setAttribute(
        "style",
        "margin: 2px 0;\n" +
          "font-size: 13px;\n" +
          "line-height: 15px;\ndisplay: flex;align-items: center;"
      );

      let app_style = "";
      if (logo) {
        let img = document.createElement("img");
        img.setAttribute(
          "style",
          "width: 18px;\n" + "height: 18px;\n" + ";\nmargin-right: 3px;\n"
        );
        img.setAttribute("src", this.logoImg);
        wrapperEle.appendChild(img);
        app_style = "display:inline";
      }

      if (!b) {
        let textEle = document.createElement("div");
        textEle.textContent = str;
        textEle.setAttribute(
          "style",
          "margin: 1px;\n" +
            "font-size: 12px;\n" +
            "font-weight: bold;\n" +
            "width: 100%;\n" +
            "color: " +
            color +
            ";\n" +
            "overflow-wrap: break-word;\n" +
            app_style
        );
        wrapperEle.appendChild(textEle);
      }

      if (b) {
        var button = document.createElement("div");
        button.style.backgroundColor = "blue"; // 设置按钮背景颜色为蓝色
        button.style.color = "#005bff"; // 设置按钮文字颜色为白色
        // 设置按钮的文本内容
        button.style.width = "40%";
        button.style.height = "15px";
        button.style.padding = "5px";
        button.style.margin = "auto";
        button.style.cursor = "pointer";
        button.style.borderRadius = "5px";
        button.style.textAlign = "center";
        button.style.lineHeight = "20px";
        button.style.color = "#fff";
        button.innerHTML = this.terx;
        wrapperEle.style.position = "absolute";
        wrapperEle.style.bottom = "3px";
        wrapperEle.style.width = "100%";
        button.addEventListener("click", this.dainji(item));
        wrapperEle.appendChild(button);
      }

      container.appendChild(wrapperEle);
    },

    async caiji() {
      let aa = this.da;

      if (aa && aa.sku) {
        let da = {
          sku: aa.sku,
          primary_image: aa.photo,
          brand: aa.brand,
          volume: aa.volume,
          price: aa.avgPrice,
          linkUrl: aa.link,
          name: aa.name,
          offer_id: aa.id,
          categoryId: aa.categoryId,
          description_category_id: aa.description_category_id,
          typeId: aa.typeId,
        };
        let retJson = await axiosInstance.post(
          `${baseURL}/api/saveProduct`,
          da
        );
        showNotify({message: "采集成功！", position: "top"});
      } else {
        showNotify({message: "此商品未采集到数据！", position: "top"});
      }
    },
    dainji(aa) {
      return async function () {
        console.log(aa);
        if (aa && aa.sku) {
          let da = {
            // categoryId: aa.category1,
            // description_category_id: aa.category2,
            // typeId: aa.category3,
            sku: aa.sku,
            primary_image: aa.photo,
            brand: aa.brand,
            volume: aa.volume,
            price: aa.avgPrice,
            linkUrl: aa.link,
            name: aa.name,
            offer_id: aa.id,
          };
          let retJson = await axiosInstance.post(
            `${baseURL}/api/saveProduct`,
            da
          );
          showNotify({message: "采集成功！", position: "top"});
        } else {
          showNotify({message: "此商品未采集到数据！", position: "top"});
        }
        console.log(aa);
      };
    },
    async appendLine(str, container, color, logo) {
      if (!color) {
        color = "black";
      }
      let wrapperEle = document.createElement("div");
      wrapperEle.setAttribute(
        "style",
        "margin: 8px 0;\n" +
          "font-size: 15px;\n" +
          "width: 386px;\ndisplay: flex;align-items: center;"
      );
      let app_style = "";
      if (logo) {
        let img = document.createElement("img");
        img.setAttribute(
          "style",
          "width: 18px;\n" + "height: 18px;\n" + ";\nmargin-right: 3px;\n"
        );
        img.setAttribute("src", this.logoImg);
        wrapperEle.appendChild(img);
        app_style = "display:inline";
      }
      let textEle = document.createElement("div");
      textEle.textContent = str;
      textEle.setAttribute(
        "style",
        "font-size: 12px;\n" +
          "font-weight: bold;\n" +
          "width: 100%;\n" +
          "color: " +
          color +
          ";\n" +
          "overflow-wrap: break-word;\n" +
          app_style
      );
      wrapperEle.appendChild(textEle);
      container.appendChild(wrapperEle);
    },

    async getStoreList() {
      console.log("getStoreList");
      // 发送 POST 请求
      let retJson = await axiosInstance.get(`${baseURL}/api/store/list`);
      let items = retJson["data"]["data"];
      console.log(items);
      this.storeList = items;
    },

    async genmaiDefault() {
      this.skuList.forEach((item) => {
        let price = item.data.price
          .trim()
          .replace(",", ".")
          .replace(" ", "")
          .replace("₽", "")
          .replace("$", "");
        console.log(price);
        item.resultPrice = parseFloat(price);
      });
    },

    async genMai() {
      if (this.active == false) {
        showToast("TqOzon提示：当前账户权限不足,请使用激活码激活！");
        return;
      }
      if (this.skuDetail.sku == null) {
        alert("请等待数据加载完成！");
        return;
      }
      if (
        document.querySelector(
          ".client-state #state-webAspects-418255-default-1"
        )
      ) {
        let ele = document.querySelector(
          ".client-state #state-webAspects-418255-default-1"
        );
        let dataState = ele.getAttribute("data-state");
        dataState = JSON.parse(dataState);
        this.skuList = [];
        for (let i in dataState["aspects"]) {
          console.log(dataState["aspects"][i]["variants"]);
          this.skuList = this.skuList.concat(
            dataState["aspects"][i]["variants"]
          );
        }
      } else {
        let ele = document.querySelector(
          "#state-webInstallmentPurchase-3354135-default-1"
        );
        let dataState = ele.getAttribute("data-state");
        dataState = JSON.parse(dataState);
        this.skuList = [];
        if (this.skuDetail.id) {
          this.skuList.replace({
            sku: this.sku,
            data: {
              searchableText: "销量" + this.skuDetail.soldCount,
              coverImage: this.skuDetail.photo,
              // price: parseFloat(this.skuDetail.avgPrice) + "",
            },
          });
        } else {
          this.skuList.replace({
            sku: this.sku,
          });
        }
      }
      this.getStoreList();
      console.log("genMai");
      // this.show = true;
    },
  },
};
</script>
<style scoped>
.van-dialog__content {
  max-height: 700px !important;
}
.wrapper {
  display: flex;
  align-items: center;
  flex-direction: column;
  max-height: 600px;
  overflow-y: scroll;
}
.div_title {
  font-size: 15px;
  line-height: 20rpx;
  text-align: left;
}
.store_list {
  width: 100%;
  border: 1px solid grey;
  max-height: 150px;
  overflow-y: scroll;
}
.sku_list {
  width: 100%;
  border: 1px solid grey;
  max-height: 500px;
  min-height: 200px;
  overflow-y: scroll;
  padding: 5px;
}
.sku_item {
  font-size: 13px;
  display: flex;
  /* align-items: center; */
  /* justify-content: center; */
  margin: 2px 0;
  border-bottom: 1px solid grey;
}
.tongyi_div {
  display: flex;
  align-items: center;
  height: 50px;
}
.handle_div {
  width: 300px;
  display: flex;
  align-items: center;
  height: 100%;
  margin: 0 20px;
}
.handle_div input {
  width: 100px;
  margin: 0 20px;
}
.check-item {
  width: 100%;
  height: 35px;
  line-height: 35px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  box-sizing: border-box;
}
.van-cell-group {
  width: 100% !important;
}
.van-checkbox--horizontal {
  width: 100% !important;
  height: 100% !important;
  margin-right: 0px !important;
}
.van-checkbox--horizontal[aria-checked="true"] {
  background-color: #dcdcdc;
}
.van-checkbox__label {
  width: 100% !important;
  height: 100% !important;
  height: 35px !important;
  line-height: 35px !important;
}
</style>
